package com.ln.spring.core;

import org.springframework.core.ResolvableType;

import java.util.HashMap;
import java.util.List;

public class ResolvableTypeDemo {

    private HashMap<Integer, List<String>> myMap;

    public void example() throws NoSuchFieldException {
        ResolvableType t = ResolvableType.forField(getClass().getDeclaredField("myMap"));
        t.getSuperType(); // AbstractMap<Integer, List<String>>
        t.asMap(); // Map<Integer, List<String>>
        System.out.printf("t.getGeneric(0).resolve(): \t%s \n", t.getGeneric(0).resolve()); // Integer
        System.out.printf("t.getGeneric(0).resolve(): \t%s \n", t.getGeneric(1).resolve()); // List
        System.out.printf("t.getGeneric(1): \t%s \n", t.getGeneric(1)); // List<String>
        System.out.printf(" t.resolveGeneric(1, 0): \t%s \n", t.resolveGeneric(1, 0)); // String
    }

    public static void main(String[] args) throws NoSuchFieldException {
        ResolvableTypeDemo demo = new ResolvableTypeDemo();
        demo.example();
    }

}
